$.ajax({
    url:"getGoodsCate",
    data:{"type":"", "categroy":""},
    type:"post",
    dataType:"json",
    success:function (val) {
        var str=`<option value="" id="sectionclass">请选择一级分类</option>`;
        val=JSON.parse(val);
        for(var i=0;i<val.length;i++){
            var cur=val[i];
            str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
        }
        $("#first").html("");
        $("#first").html(str);
    }
});
$("#first").change(getsection);
$("#section").change(getthree);
function getsection() {
    var selectoption= $("#first option:selected");
    var id=selectoption.attr("name");
    $.ajax({
        url:"getGoodsCate",
        data:{"type":1, "categroy":id},
        type:"post",
        dataType:"json",
        async:false,
        success:function (val) {
            var str=`<option value="" id="sectionclass">请选择二级分类</option>`;
            val=JSON.parse(val);
            for(var i=0;i<val.length;i++){
                var cur=val[i];
                str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
            }
            $("#section").html("");
            $("#section").html(str);
        }
    })
}
function getthree() {
    var selectoption= $("#section option:selected");
    var id=selectoption.attr("name");
    $.ajax({
        url:"getGoodsCate",
        data:{"type":2, "categroy":id},
        type:"post",
        dataType:"json",
        async:false,
        success:function (val) {
            var str=`<option value="" id="threeclass">请选择三级分类</option>`;
            val=JSON.parse(val);

            for(var i=0;i<val.length;i++){
                var cur=val[i];
                str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
            }
            $("#three").html("");
            $("#three").html(str);
        }
    })
}

$("#three").change(function () {
    var $threeoption=$("#three option:selected");
    var id=$threeoption.attr("name");
    $("#threeid").val(id);
});

function countChoices(obj) {
    max = 3;
    box0 = $("input[type=checkbox]").get(0).checked;
    box1 = $("input[type=checkbox]").get(1).checked;
    box2 = $("input[type=checkbox]").get(2).checked;
    box3 = $("input[type=checkbox]").get(3).checked;
    box4 = $("input[type=checkbox]").get(4).checked;
    box5 = $("input[type=checkbox]").get(5).checked;
    count = (box0 ? 1 : 0) + (box1 ? 1 : 0) + (box2 ? 1 : 0)+ (box3 ? 1 : 0)+(box4 ? 1 : 0)+(box5 ?1 : 0);
    if (count > max) {
        iosOverlay({
            text: `最多只能选${max}个`,
            duration: 2e3,
            icon: "../../images/cross.png"
        });
        obj.checked = false;
    }};
$("#submit").click(
    function () {
        var ccimgval=$("#shiimg").val();
        console.log(ccimgval);
        var bannerimgok=false;
        var goodimgok=false;
        var bannerimgval=$(".bannerimg");
        var gooddescimg=$(".filemore");
        console.log($("input[name=spec]").val());
        var num1=false;
        var num2=false;
        if($("#goodclass").html()=="" ){
            alert("请选择商品分类！");
            return false
        }else if(!nameok){
            iosOverlay({
                text: `商品名太长了！`,
                duration: 2e3,
                icon: "../../images/cross.png"
            });
            return false
        }else if(ccimgval==""){
            iosOverlay({
                text: `请上传商品橱窗图！`,
                duration: 2e3,
                icon: "../../images/cross.png"
            });
            return false
        }else if(!$("input[name=spec]").val()){
            iosOverlay({
                text: `请填写商品规格！`,
                duration: 2e3,
                icon: "../../images/cross.png"
            });
            return false
        }
        for(var i=0;i<bannerimgval.length;i++){
            var curval=bannerimgval[i].value;
            if(!curval){
                bannerimgok=true;
                iosOverlay({
                    text: `商品banner图必须为3张！`,
                    duration: 2e3,
                    icon: "../../images/cross.png"
                });
                return false
            }
        }
        for(var j=0;j<1;j++){
            var currimg=gooddescimg[j].value;
            if(!currimg){
                goodimgok=true;
                iosOverlay({
                    text: `请上传商品详情介绍图！`,
                    duration: 2e3,
                    icon: "../../images/cross.png"
                });
                return false
            }
        }
    }
);
$("#reset").click(function () {
    $("#goodclass").html("");
});
/*
$(".num").each(function (index, item) {
    $(this).blur(function () {
        var val=this.value;
        var tip=document.getElementsByClassName("tip");
        if(!/^\d+$/.test(val) || val===""){
            $(tip[index]).show()
        }else{
            $(tip[index]).hide();
        }
    })
});*/
/*$("input[name=shop_name]").blur(function (){
        var shop_nameval=this.value.length;
        if(shop_nameval>=40){
            var str=`<label style="vertical-align: middle;color: red;display: none" class="tip">商品名字数不能超过40个字,</label>
`;
        }else{
            $(tip[index]).hide();
        }
    });*/

/*商品原价限制格式*/
$(".newPrice").blur(function(){
    var val=$(this).val();
    if(isNaN(val)){
        $($(".tip").get(0)).html("请输入数字格式").show();
    }else{
        valary=val.split(".");
        console.log(valary[1]);
        if(Number(valary[1])>=100){
            $($(".tip").get(0)).html("商品价格请精确到小数点后两位,如:56.49,否则，价格将会四舍五入至小数点后两位").show();
        }else{
            $($(".tip").get(0)).html("").hide();
        }
        val=parseFloat(val);
        $("input[name=shop_end_money]").val(val.toFixed(2))
    }

});
$(".oldPrice").blur(function(){
    var val=$(this).val();
    if(isNaN(val)){
        $($(".tip").get(1)).html("请输入数字格式").show();
    }else{
        valary=val.split(".");
        console.log(valary[1]);
        if(Number(valary[1])>=100){
            $($(".tip").get(1)).html("商品价格请精确到小数点后两位,如:56.49,否则，价格将会四舍五入至小数点后两位").show();

        }else{
            $($(".tip").get(1)).html("").hide();
        }
        val=parseFloat(val);
        $("input[name=shop_start_money]").val(val.toFixed(2))
    }

});

/*商品名字数不能超过40个字*/

var nameok=true;
$("input[name=shop_name]").keydown(function(){
    var shop_nameval=this.value.length;
    if(shop_nameval>40 ){
        nameok=false;
      $("#shopNameCheckTip").html(`商品名字数不能超过40个字,已超出${shop_nameval-39}个字`).css({"color":"red"})
    }else{
        nameok=true
        $("#shopNameCheckTip").html(`格式正确！`).css({"color":"green"});
    }
});
$("input[name=shop_name]").blur(function(){
    if(!$(this).val()){
        nameok=false
        $("#shopNameCheckTip").html(`请输入商品名！`).css({"color":"red"});
    }
});


/*添加规格 */
var typeary=[];
/*商品规格 颜色选择*/
$(".colorcheck").each(function (index,item) {
    $(item).click(
        function () {
            var index=$(this).index();
            $(".colorcheck").each(function (index, item) {
                    if($(this).is(':checked')){
                        // alert(index)
                        $($(".colorinput").get(index)).attr("disabled",false)
                    }else {

                        $($(".colorinput").get(index)).attr("disabled",true)
                    }
                }
            )
        });
});
/*商品规格 尺码选择*/

var color=[];
var size=[];
$("#bok").click(function () {
    var strclassname="";
    var ok=true;
    $("select>option:selected").each(function (index, item) {
        if($(item).val()==""){
            ok=false;
        }
        strclassname+=$(item).html()+">"
    });
    if(ok){
        strclassname=strclassname.substr(0,strclassname.length-1);
        var $threeoption=$("#three option:selected");
        var threeId=$threeoption.attr("name");
        console.log(threeId);
        $.ajax({
            url:"getCategroySpec",
            data:{"type":3,"categroy":threeId},
            type:"post",
            async:false,
            dataType:"json",
            success:function (res) {
                console.log(res);
                if(res.length){
                    /*有两种规格的情况*/
                    if(res.length==2){
                        typeary=[];
                        for(var i=0;i<res.length;i++){
                            var cur=res[i];
                            typeary.push(cur.spec_name)
                        }
                       var str=`<a class="btn btn-info" role="button" data-toggle="collapse" id="editType" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">添加商品属性</a>
                    <div class="collapse" id="collapseExample">
                        <div class="well" style="background-color: #fff;" >
                                <div class="row" style="text-align: center" id="color">
                                    <label class="col-sm-2" style="font-weight: bold">${typeary[0]}：</label>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled>
                                    </div>
                                     <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled >
                                    </div>
                                </div>
                                <div class="row" style="text-align: center">
                                    <label class="col-sm-2"></label>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input  class="colorinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled >
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                     <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                </div>
                                <div class="row" style="text-align: center">
                                    <label class="col-sm-2"></label>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input  class="colorinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled >
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                     <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                </div>
                                <div class="row" style="text-align: center;margin-top: 20px">
                                    <label class="col-sm-2" style="font-weight: bold">${typeary[1]}:</label>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input  class="sizeinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled >
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                </div>
                                <div class="row" style="text-align: center">
                                    <label class="col-sm-2"></label>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input  class="sizeinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled >
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                </div>
                                     <div class="row" style="text-align: center">
                                    <label class="col-sm-2"></label>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input  class="sizeinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled >
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="sizecheck"><input class="sizeinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                </div>
                                <div class="row" style="text-align: center;margin-top: 20px">
                                    <button class="btn btn-default" type="button" id="addtype">确定生成</button>
                                </div>

                        </div>
                    </div>`;
                        $("#addType1").html(str);
                        $("#goodclass").html(strclassname);
                        $("#editType").trigger("click");
                        $(".colorcheck").each(function (index,item) {
                            $(item).click(
                                function () {
                                    var index=$(this).index();
                                    $(".colorcheck").each(function (index, item) {
                                            if($(this).is(':checked')){
                                                // alert(index)
                                                $($(".colorinput").get(index)).attr("disabled",false)
                                            }else {
                                                $($(".colorinput").get(index)).attr("disabled",true)
                                            }
                                        }
                                    )
                                });
                        });
                        /*商品规格 尺码选择*/
                        $(".sizecheck").each(function (index,item) {
                            $(item).click(
                                function () {
                                    var index=$(this).index();
                                    $(".sizecheck").each(function (index, item) {
                                            if($(this).is(':checked')){
                                                // alert(index)
                                                $($(".sizeinput").get(index)).attr("disabled",false);
                                            }else {

                                                $($(".sizeinput").get(index)).attr("disabled",true)
                                            }
                                        }
                                    )
                                });
                        });
                        $(document).on("click","#addtype",function () {
                            color=[];
                            size=[];
                            var str='';
                            var bok=true;
                            $(".colorcheck").each(function (index, item) {
                                if(item.checked){
                                    var val=$($(".colorinput").get(index)).val();

                                    if(val){
                                        color.push(val)
                                    }else{
                                        bok=false;
                                        return;
                                    }
                                }
                            });
                            $(".sizecheck").each(function (index, item) {
                                if(item.checked){
                                    var val=$($(".sizeinput").get(index)).val();
                                    if(val){
                                        size.push(val)
                                    }else{
                                        bok=false;
                                        return;
                                    }
                                }
                            });
                            console.log(color,size);
                            if(bok){
                                for (var i=0;i<color.length;i++){
                                    var curcolor=color[i];
                                    for(var j=0;j<size.length;j++){
                                        var cursize=size[j];
                                        str+=`<tr style="text-align: center">
                                                <td class="col-sm-2">${curcolor}</td>
                                                <td class="col-sm-2">${cursize}</td>
                                                <td class="col-sm-2"><input type="text" class="inputcount" value="0"></td>
                                                <td class="col-sm-2"><input type="text" class="inputwramming" value="10"></td>
                                            </tr>`
                                    }
                                    var tb=`
                                    <div class="form-inline pull-right" style="margin: 30px 0" >
  <div class="form-group">
    <label for="exampleInputEmail2">批量设置:</label>
    <input type="text" class="form-control" style="width:120px" id="stock" placeholder="库存">
    <input type="text" class="form-control" style="width:120px" id="wraningStock" placeholder="预警库存"><button class="btn btn-default" type="button" id="PLSZbtn">确定</button>
  </div>
</div>
                                   <div class="row" style="margin-top: 20px">
                                    <table class="goodtype-wrapper table table-striped"style="width: 100%">
                                        <thead  style="background-color: #eeeeee;">
                                            <tr style="text-align: center;height: 30px">
                                                <td class="col-sm-2">${typeary[0]}</td>
                                                <td class="col-sm-2">${typeary[1]}</td>
                                                <td class="col-sm-2"><i style="color: red">*</i>库存</td>
                                                <td class="col-sm-2">警戒库存</td>
                                            </tr>
                                        </thead>
                                        <tbody id="tbody">
                                        ${str}
                                        </tbody>
                                    </table>
                                </div>
                                <div class="row" style="text-align: center">
                                    <button type="button" class="btn btn-success" id="typeOk">确定</button>
                                </div>`
                                    var arykucun=[];

                                }
                                $(".well").append(tb);
                                /*点击确定生成数据*/
                                $("#PLSZbtn").click(function(){
                                    var stockval=Number($("#stock").val());
                                    var wraningStockval=$("#wraningStock").val();
                                    if(stockval ){
                                        if(!isNaN(stockval)){
                                            $(".inputcount").val(stockval);
                                        }else{
                                            iosOverlay({
                                                text: "库存必须为数字!",
                                                duration: 2e3,
                                                icon: "../../images/cross.png"
                                            });
                                        }

                                    }
                                    if(wraningStockval){
                                        if(!isNaN(wraningStockval)){
                                            $(".inputwramming").val(wraningStockval);
                                        }else{
                                            iosOverlay({
                                                text: "预警库存必须为数字!",
                                                duration: 2e3,
                                                icon: "../../images/cross.png"
                                            });}

                                    }


                                });
                                /*点击确定生成数据*/
                                $(document).on("click","#typeOk",function () {
                                    console.log(111)
                                    var trcount=$("tbody tr").length;
                                    var datatye=[];
                                    if(trcount){
                                        for(var  i =0;i<trcount;i++){
                                            var str="";

                                            str=$($($("tbody tr").get(i)).children("td")[0]).html()+"|&|"+$($($("tbody tr").get(i)).children("td")[1]).html()+"|&|"+$($($("tbody tr").get(i)).children("td")[2]).children().val()+"|&|"+$($($("tbody tr").get(i)).children("td")[3]).children().val();
                                            datatye.push(str);
                                        }
                                        var str=`<input type="text" hidden name="spec" value="${datatye}">`
                                        $("#typewrapper").html(str);
                                        console.log($("input[name=spec]").val());
                                        $(this).html("数据已生成").removeClass("btn-info").addClass("btn-success");
                                    }else{
                                        iosOverlay({
                                            text: "请先选择规格!",
                                            duration: 2e3,
                                            icon: "../../images/cross.png"
                                        });
                                    }
                                });
                               /* $("#typeOk").click(function () {
                                    var trcount=$("tbody tr").length;
                                    var datatye=[];
                                    if(trcount){
                                        for(var  i =0;i<trcount;i++){
                                            var str="";

                                            str=$($($("tbody tr").get(i)).children("td")[0]).html()+"|&|"+$($($("tbody tr").get(i)).children("td")[1]).html()+"|&|"+$($($("tbody tr").get(i)).children("td")[2]).children().val()+"|&|"+$($($("tbody tr").get(i)).children("td")[3]).children().val();
                                            datatye.push(str);
                                        }
                                        var str=`<input type="text" hidden name="spec" value="${datatye}">`
                                        $("#typewrapper").html(str);
                                        console.log($("input[name=spec]").val());
                                        $(this).html("数据已生成").removeClass("btn-info").addClass("btn-success");
                                    }else{
                                        iosOverlay({
                                            text: "请先选择规格!",
                                            duration: 2e3,
                                            icon: "../../images/cross.png"
                                        });
                                    }
                                })*/
                            }else{
                                iosOverlay({
                                    text: "请填写完整信息!",
                                    duration: 2e3,
                                    icon: "../../images/cross.png"
                                });
                            }


                        })
                    }

                    else{
                        if(confirm("必须先添加二级规格，是否去添加！")){
                            window.location.href="/admin/category/specadd"
                        }else{
                            return false;
                        }
                    }
                    /*else if(res.length==1){
                        typeary=[];
                        typeary.push(res[0].spec_name)
                        var str=`<a class="btn btn-info" role="button" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">添加商品属性</a>
                    <div class="collapse" id="collapseExample">
                        <div class="well" style="background-color: #fff;" >
                                <div class="row" style="text-align: center" id="color">
                                    <label class="col-sm-2" style="font-weight: bold">${typeary[0]}：</label>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled >
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled >
                                    </div>
                                </div>
                                <div class="row" style="text-align: center">
                                    <label class="col-sm-2"></label>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input  class="colorinput" type="text" value="" style="width: 50px; border: 1px solid #CCCCCC" disabled >
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="checkbox" class="colorcheck"><input class="colorinput" type="text" value="" style="width: 50px;border: 1px solid #CCCCCC" disabled>
                                    </div>
                                </div>
                                <div class="row" style="text-align: center;margin-top: 20px">
                                    <button class="btn btn-default" type="button" id="addtype">确定生成</button>
                                </div>
                                <div class="row" style="margin-top: 20px">
                                    <table class="goodtype-wrapper table table-striped"style="width: 100%">
                                        <thead  style="background-color: #eeeeee;">
                                            <tr style="text-align: center;height: 30px">
                                                <td class="col-sm-2">${typeary[0]}</td>
                                                <td class="col-sm-2"><i style="color: red">*</i>库存</td>
                                                <td class="col-sm-2">警戒库存</td>
                                            </tr>
                                        </thead>
                                        <tbody id="tbody">
                                        </tbody>
                                    </table>
                                </div>
                                <div class="row" style="text-align: center">
                                    <button type="button" class="btn btn-info" id="typeOk">确定</button>
                                </div>
                        </div>
                    </div>`;
                        $("#addType1").html(str);
                        $("#goodclass").html(strclassname);
                        $("#editType").trigger("click");
                        $(".colorcheck").each(function (index,item) {
                            $(item).click(
                                function () {
                                    var index=$(this).index();
                                    $(".colorcheck").each(function (index, item) {
                                            if($(this).is(':checked')){
                                                // alert(index)
                                                $($(".colorinput").get(index)).attr("disabled",false)
                                            }else {
                                                $($(".colorinput").get(index)).attr("disabled",true)
                                            }
                                        }
                                    )
                                });
                        });
                        $(document).on("click","#addtype",function () {
                            color=[];
                            var str='';
                            var bok=true;
                            $(".colorcheck").each(function (index, item) {
                                if(item.checked){
                                    var val=$($(".colorinput").get(index)).val();

                                    if(val){
                                        color.push(val)
                                    }else{
                                        bok=false;
                                        return;
                                    }
                                }
                            });
                           if(bok){
                               for (var i=0;i<color.length;i++){
                                   var curcolor=color[i];
                                   str+=`<tr style="text-align: center">
                                                <td class="col-sm-2">${curcolor}</td>
                                                <td class="col-sm-2"><input type="text" class="inputcount" value="0"></td>
                                                <td class="col-sm-2"><input type="text" class="inputwramming" value="10"></td>
                                            </tr>`
                                   var arykucun=[];
                               }
                               $("#tbody").html(str);
                               $("#typeOk").click(function () {
                                   var trcount=$("tbody tr").length;
                                   var datatye=[];
                                   if(trcount){
                                       for(var  i =0;i<trcount;i++){
                                           var str="";
                                           console.log($($("tbody tr").get(i)).children("td > .inputcount").val());
                                           str=$($($("tbody tr").get(i)).children("td")[0]).html()+'/'+$($($("tbody tr").get(i)).children("td")[1]).children().val()+'/'+$($($("tbody tr").get(i)).children("td")[2]).children().val();
                                           datatye.push(str);
                                       }
                                       var str=`<input type="text" hidden name="spec" value="${datatye}">`;
                                       $("#typewrapper").html(str);
                                       $(this).html("数据已生成").removeClass("btn-info").addClass("btn-success");
                                   }else{
                                       iosOverlay({
                                           text: "请先选择规格!",
                                           duration: 2e3,
                                           icon: "../../images/cross.png"
                                       });
                                   }
                               })
                           }else{
                               iosOverlay({
                                   text: "请填写完整信息!",
                                   duration: 2e3,
                                   icon: "../../images/cross.png"
                               });
                           }


                        })
                    }*/
                }
                else{
                    if(confirm("还没有添加分类规格是否去添加！")){
                        window.location.href="/admin/category/specadd"
                    }else{
                        return false;
                    }
                }
            }
        })
    }else{
        iosOverlay({
            text: "请选择完整分类",
            duration: 2e3,
            icon: "../../images/cross.png"
        });
        return;
    }
});
/*添加表格*/
$(document).on("click",".addsize",function(){
    var str=` <div class=" form-group newsize" >
                                <label  class="col-sm-2  control-label"></label>
                                <div class="  col-xs-2">
                                    <input type="text" class="form-control" name="spec_two_name[]" placeholder="${typeary[1]}">
                                </div>
                                <div class="  col-xs-2">
                                    <input type="text" class="form-control" name="stock_num[]" placeholder="库存">
                                </div>
                                <div class="  col-xs-3">
                                    <input type="text" class="form-control" name="=warning_num[]" placeholder="库存预警">
                                </div>
                                <!--
                                <div class="  col-xs-2">
                                    <input type="text" class="form-control" placeholder="价格">
                                </div>-->
                                
                                <div class="  col-xs-1">
                                    <button type="button" class="btn btn-danger remove-size" >×</button>
                                </div>
                            </div>`;
    var addparent=$(this).parent().parent().parent().parent();
    console.log(addparent);
    addparent.append(str);
});
$(document).on("click",".addsizetype1",function(){
    var str=` <div class=" form-group newsize" >
                                <label  class="col-sm-2  control-label"></label>
                                <div class="  col-xs-2">
                                    <input type="text" class="form-control" name="spec_one_name[]" placeholder="${typeary[0]}">
                                </div>
                                <div class="  col-xs-2">
                                    <input type="text" class="form-control" name="stock_num[]" placeholder="库存">
                                </div>
                                <div class="  col-xs-3">
                                    <input type="text" class="form-control" name="=warning_num[]" placeholder="库存预警">
                                </div>
                                <!--
                                <div class="  col-xs-2">
                                    <input type="text" class="form-control" placeholder="价格">
                                </div>-->
                                <div class="  col-xs-1">
                                    <button type="button" class="btn btn-danger remove-size" >×</button>
                                </div>
                            </div>`;
    var addparent=$(this).parent().parent().parent().parent();
    console.log(addparent);
    addparent.append(str);
});
$(document).on("click",".remove-size",function () {
    var parent=$(this).parent().parent();
    parent.remove();
});
$(document).on("click",".remove-color",function () {
    var parent=$(this).parent().parent().parent().parent();
    parent.remove();
});
$(document).on("click","#addcolor",function () {
    var str=`<div class=" form-group goodtype-wrapper">
                    <label  class="col-sm-2 control-label"></label>
                    <div class="col-sm-8 " style="border: 1px solid #CCCCCC; padding-top: 15px" >
                        <div class=" form-group">
                            <label  class="col-sm-2 control-label">${typeary[0]}:</label>
                            <div class="col-sm-2" >
                                <input type="text" class="form-control" name="spec_one_name[]" placeholder="${typeary[0]}">
                            </div>
                        </div>

                        <div class=" size-wrapper">
                            <div class=" form-group " >
                                <label  class="col-sm-2  control-label">${typeary[1]}:</label>
                                <div class="  col-xs-2">
                                    <input type="text" class="form-control" name="spec_two_name[]" placeholder="${typeary[1]}">
                                </div>
                                <div class="  col-xs-2">
                                    <input type="text" class="form-control"  name="stock_num[]" placeholder="库存">
                                </div>
                                <div class="  col-xs-3">
                                    <input type="text" class="form-control"name="shop_min_num[]" placeholder="库存预警">
                                </div><!--
                                 <div class="  col-xs-2">
                                    <input type="text" class="form-control"name="shop_min_num" placeholder="价格">
                                </div>-->
                                <div class="col-xs-1"><button type="button" class="btn btn-info addsize">+</button></div>
                            </div>
                        </div>
                    </div>
                </div>`
    $("#addbtnwrapper").before(str)
});

var num=3;
/*多张图片添加图片按钮*/
$(document).on("click","#addImg",function () {
    var str="";
    num++;
    if(num>=21){
        iosOverlay({
            text: "最多添加20张图片！",
            duration: 2e3,
            icon: "../../images/cross.png"
        });
        return;
    }
    var str=` <div class="col-sm-le">
                        <div class="imgupload-box full">
                            <section class="img-section">
                                <div class="z_photo upimg-div clear">
                                    <section class="z_file fl" style="display: block;">
                                        <img src="/images/bg-tu.png" class="add-img">
                                        <input type="file" name="detail_path[]" id="shi0${num}" class="file01 filemore" value="" accept="image/jpg,image/jpeg,image/png,image/bmp">
                                    </section>
                                </div>
                                <p class="up-p up-p-center"><span class="up-span">第${num}张</span></p>
                            </section>
                        </div>
                    </div>`;
    $(this).parent().parent().before(str)

});
/*选择单张图片上传按钮*/
$("#singleBtn").click(function () {
    var str=`<div class="imgupload-box full">
                        <section class="img-section">
                            <div class="z_photo upimg-div clear">
                                <section class="z_file fl" style="display: block;">
                                    <img src="/images/bg-tu.png" class="add-img">
                                    <input type="file" name="detail_path[]" id="single" class="file01 " value="" accept="image/jpg,image/jpeg,image/png,image/bmp">
                                </section>
                            </div>
                            <p class="up-p"><span class="up-span">最多可以上传1张图片</span></p>
                        </section>
                    </div>`;
    $("#imgWrapper").html(str);
});
/*选择多张图片上传按钮*/
$("#moreBtn").click(function () {
    var str=` <div class="col-sm-le">
                        <div class="imgupload-box full">
                            <section class="img-section">
                                <div class="z_photo upimg-div clear">
                                    <section class="z_file fl" style="display: block;">
                                        <img src="/images/bg-tu.png" class="add-img">
                                        <input type="file" name="detail_path[]" id="shi01" class="file01 filemore" value="" accept="image/jpg,image/jpeg,image/png,image/bmp">
                                    </section>
                                </div>
                                <p class="up-p up-p-center"><span class="up-span">第1张</span></p>
                            </section>
                        </div>
                    </div>
                    <div class="col-sm-le">
                        <div class="imgupload-box full">
                            <section class="img-section">
                                <div class="z_photo upimg-div clear">
                                    <section class="z_file fl" style="display: block;">
                                        <img src="/images/bg-tu.png" class="add-img">
                                        <input type="file" name="detail_path[]" id="shi02" class="file01 filemore" value="" accept="image/jpg,image/jpeg,image/png,image/bmp">
                                    </section>
                                </div>
                                <p class="up-p up-p-center"><span class="up-span">第2张</span></p>
                            </section>
                        </div>
                    </div>
                    <div class="col-sm-le">
                        <div class="imgupload-box full">
                            <section class="img-section">
                                <div class="z_photo upimg-div clear">
                                    <section class="z_file fl" style="display: block;">
                                        <img src="/images/bg-tu.png" class="add-img">
                                        <input type="file" name="detail_path[]" id="shi03" class="file01 filemore" value="" accept="image/jpg,image/jpeg,image/png,image/bmp">
                                    </section>
                                </div>
                                <p class="up-p up-p-center"><span class="up-span">第3张</span></p>
                            </section>
                        </div>
                    </div>
                    <div class="col-sm-le">
                        <div class="imgupload-box full">
                            <button type="button" class="btn btn-default" id="addImg">增加图片</button>
                        </div>
                    </div>`;
        $("#imgWrapper").html(str);
});


